package com.qckj.amz.controller;

import com.qckj.amz.domain.ConfigUpc;
import com.qckj.amz.service.IConfigUpcService;
import com.qckj.common.annotation.Log;
import com.qckj.common.core.controller.BaseController;
import com.qckj.common.core.domain.AjaxResult;
import com.qckj.common.core.page.TableDataInfo;
import com.qckj.common.enums.BusinessType;
import com.qckj.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 产品编码配置Controller
 *
 * @author luchuan
 * @since 1.0 2022-09-14
 */
@RestController
@RequestMapping("/amz/configUpc")
public class ConfigUpcController extends BaseController {
    @Autowired
    private IConfigUpcService configUpcService;

    /**
     * 查询产品编码配置列表
     */
    @PreAuthorize("@ss.hasPermi('amz:configUpc:list')")
    @GetMapping("/list")
    public TableDataInfo list(ConfigUpc configUpc) {
        Page<ConfigUpc> page = configUpcService.findConfigUpcPage(configUpc);
        return getDataTable(page);
    }

    /**
     * 导出产品编码配置列表
     */
    @PreAuthorize("@ss.hasPermi('amz:configUpc:export')")
    @Log(title = "产品编码配置", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ConfigUpc configUpc) {
        List<ConfigUpc> list = configUpcService.findConfigUpcList(configUpc);
        ExcelUtil<ConfigUpc> util = new ExcelUtil<>(ConfigUpc.class);
        return util.exportExcel(list, "configUpc");
    }

    /**
     * 获取产品编码配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('amz:configUpc:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(configUpcService.findById(id));
    }

    /**
     * 新增产品编码配置
     */
    @PreAuthorize("@ss.hasPermi('amz:configUpc:add')")
    @Log(title = "产品编码配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ConfigUpc configUpc) {
        configUpcService.save(configUpc);
        return AjaxResult.success();
    }

    /**
     * 修改产品编码配置
     */
    @PreAuthorize("@ss.hasPermi('amz:configUpc:edit')")
    @Log(title = "产品编码配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ConfigUpc configUpc) {
        configUpcService.save(configUpc);
        return AjaxResult.success();
    }

    /**
     * 删除产品编码配置
     */
    @PreAuthorize("@ss.hasPermi('amz:configUpc:remove')")
    @Log(title = "产品编码配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        configUpcService.deleteByIds(Arrays.asList(ids));
        return AjaxResult.success();
    }
}
